package com.hxj.ecokey.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hxj.ecokey.entity.UserRanking;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserRankingMapper extends BaseMapper<UserRanking> {
    @Select("SELECT id, user_id, name, avatar, carbon_amount, rank_type, " +
            "(SELECT COUNT(*) + 1 FROM user_ranking r2 " +
            "WHERE r2.rank_type = #{rankType} AND r2.carbon_amount < r1.carbon_amount) AS rank " +
            "FROM user_ranking r1 " +
            "WHERE rank_type = #{rankType} " +
            "ORDER BY carbon_amount ASC LIMIT 100")
    List<UserRanking> selectRankingList(Integer rankType);
}
